package com.ian.controller;

import com.common.util.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api("地图存储信息相关API")
@RestController
public class StorageController {
    @Autowired
    RedisTemplate redisTemplate;

    @ApiOperation("存储经纬度及地址信息")
    @PostMapping("/saveStorage")
    public ResultMsg saveStorage(@RequestParam("lnglat") String lnglat, @RequestParam("address") String address) {
        redisTemplate.opsForValue().set("lnglat", lnglat);
        redisTemplate.opsForValue().set("address", address);
        return ResultMsg.success("存储成功~", lnglat + "," + address);
    }

    @ApiOperation("取出经纬度及地址信息")
    @GetMapping("/getStorage")
    public Map getStorage() {
        Map map = new HashMap();
        map.put("lnglat", redisTemplate.opsForValue().get("lnglat"));
        map.put("address", redisTemplate.opsForValue().get("address"));
        return map;
    }

    @ApiOperation(("存储地图点击位置经纬度"))
    @PostMapping("/savePosition")
    public ResultMsg savePosition(@RequestParam("position") String position) {
        redisTemplate.opsForValue().set("position", position);
        return ResultMsg.success("存储成功~", position);
    }

    @ApiOperation("取出地图点击位置经纬度")
    @GetMapping("/getPosition")
    public Map getPosition() {
        Map map = new HashMap();
        map.put("position", redisTemplate.opsForValue().get("position"));
        return map;
    }
}
